package org.yibinxueyuan.drawcard.controller;


import org.springframework.context.support.ApplicationObjectSupport;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.yibinxueyuan.drawcard.entity.Cardinfo;
import org.yibinxueyuan.drawcard.service.CardInfoService;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/ajax")
public class IndexAjaxController extends ApplicationObjectSupport {
    @Resource(name = "CardinfoServiceImpl")
    private CardInfoService cardInfoService;


    /**
     * 抽卡(单抽,10连)
     */
    @RequestMapping("/getcards")
    public List<Cardinfo> getCards(Integer number){
        //随机获取number张卡片
        List<Cardinfo> cardinfos = cardInfoService.getCardsByRandom(number);
        return cardinfos;
    }


    /**
     *  获取默认的卡片
     */
    @RequestMapping(value = {"","/","/index"})
    public List<Cardinfo>  index(Model m){
        Cardinfo cardinfoBean = (Cardinfo) this.getApplicationContext().getBean("cardinfoBean");
        cardinfoBean.setCardName("????");
        cardinfoBean.setCardAddress("https://www.ali213.net/zt/genshiimpact/sim/images/wz.png");
        /**
         * 加入到list数组中
         */
        List<Cardinfo> listCardinfos = (List<Cardinfo>) this.getApplicationContext().getBean("ListCardinfoBean");
        listCardinfos.clear();
        listCardinfos.add(cardinfoBean);
        return listCardinfos;
    }

}
